<?php if (!defined('SERVER_ROOT')) { exit('No direct script access allowed');}
$this->template->title = 'Thêm nơi công tác mới cho cán bộ';
$v_pop_win = isset($_REQUEST['pop_win']) ? '_pop_win' : '';
$this->template->display('dsp_header' . $v_pop_win . '.php');

?>

<form name="frmMain_phanto" method="post" id="frmMain_phanto" action=""><?php
    echo $this->hidden('controller', $this->get_controller_url());
    echo $this->hidden('hdn_dsp_single_method', 'dsp_single_to');
    echo $this->hidden('hdn_dsp_all_method', 'dsp_single_to');
    echo $this->hidden('hdn_update_method', 'update_phanto');
    echo $this->hidden('hdn_delete_method', 'delete_phanto');
    echo $this->hidden('hdn_item_id', $var_macanbo);
    echo $this->hidden('pop_win', $v_pop_win);
    ?>
    <h4 style="text-align: center; ">Thêm mới nơi công tác </h4>
     <div class="Row">
        <div class="left-Col">Từ ngày: <label class="required">(*)</label></div>
        <div class="right-Col">
            <input type="text" id="txt_begin_date" name="txt_begin_date" data-allownull="no" class="inputbox" data-validate="date"
                   data-name="ngày bắt đầu"  value="<?php echo date("d/m/Y"); ?>"  />
            <img class="btndate" style="cursor:pointer" id="btnDate" src="<?php echo SITE_ROOT; ?>public/images/calendar.gif" onclick="DoCal('txt_begin_date')">
        </div>
    </div>
    <div class="Row">
        <div class="left-Col">Chọn đơn vị <label class="required">(*)</label></div>
        <div class="right-Col">
            <select id="cbx_MA_DON_VI"
            name="cbx_MA_DON_VI" style="width: 96%"
            onchange="get_to_by_donvi(this.value)">
                <?php while ($arr = $arr_all_donvi->FetchRow()): ?>
                    <?php
                    $MA = $arr['MA_DON_VI'];
                    $TEN = $arr['TEN_DON_VI'];
                    ?>
                    <?php if ($MA_DON_VI == $MA): ?>
                        <option value="<?php echo $MA; ?>" selected="selected"><?php echo $TEN; ?></option>
                    <?php else: ?>
                        <option value="<?php echo $MA; ?>" ><?php echo $TEN; ?></option>
                    <?php endif ?>
                <?php endwhile; ?>
            </select>
        </div>
    </div>
    <div class="Row" id="div_cbx_tochuyenmon">
        <div class="left-Col">Tổ/bộ môn <label class="required">(*)</label></div>
        <div class="right-Col">
            <select id="cbx_MA_TO_CHUYEN_MON"
             name="cbx_MA_TO_CHUYEN_MON" style="width: 96%">
            </select>
        </div>
    </div>

    <div class="Row">
        <div class="left-Col">Chức vụ: <label class="required">(*)</label></div>
        <div class="right-Col">
            <select id="cbx_MA_CHUC_VU"  name="cbx_MA_CHUC_VU" style="width: 96%;">
                <?php while ($arr = $arr_all_chucvu->FetchRow()): ?>
                    <?php
                    $MA = $arr['MA_CHUC_VU'];
                    $TEN = $arr['TEN_CHUC_VU'];
                    ?>
                    <?php if ($MA_CHUC_VU == $MA): ?>
                        <option value="<?php echo $MA; ?>" selected="selected"><?php echo $TEN; ?></option>
                    <?php else: ?>
                        <option value="<?php echo $MA; ?>" ><?php echo $TEN; ?></option>
                    <?php endif ?>
                <?php endwhile; ?>
            </select>
        </div>
    </div>

<div class="button-area">
    <input type="button" name="update" class = 'button' value="Cập nhật" onclick="btn_phanto_update_onclick();"/>
    <?php $v_back_action = ($v_pop_win === '') ? 'btn_back_onclick();' : 'try{window.parent.hidePopWin();}catch(e){window.close();};'; ?>
    <input type="button" name="cancel" class = 'button' value="Bỏ qua" onclick="<?php echo $v_back_action; ?>"/>
</div>
</form>
<script>
    function get_to_by_donvi(madonvi){
              $.ajax({url: "<?php echo SITE_ROOT; ?>qlcb/canbo/dsp_cbx_tochuyenmon/" + madonvi, success: function(result) {
                $("#div_cbx_tochuyenmon").html(result);
            }
        });
    }
    function btn_phanto_update_onclick() {
        var f = document.frmMain_phanto;
        m = $("#controller").val() + 'insert_thuocto/0/';
        var xObj = new DynamicFormHelper('', '', f);
        if (xObj.ValidateForm(f)) {
            $("#frmMain_phanto").attr("action", m);
            f.submit();
        }
    }
</script>
<?php $this->template->display('dsp_footer' . $v_pop_win . '.php');